	package de.earthquake;

import model.EarthquakeEntry;
import android.app.Activity;
import android.os.Bundle;

import com.google.gson.Gson;

public class FragmentDetailActivity extends Activity {
	private static final String TAG = FragmentDetailActivity.class.getCanonicalName();

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.container);
		Gson gson = new Gson();
		String earthquakeJson = null;
		if (savedInstanceState == null) {
			earthquakeJson = getIntent().getExtras().getString(CONSTANTS.EARTHQUAKE_JSON);
		} else {
			earthquakeJson = savedInstanceState.getString(CONSTANTS.EARTHQUAKE_JSON);
		}
		EarthquakeEntry entry = gson.fromJson(earthquakeJson, EarthquakeEntry.class);
        EarthquakeDetail details = EarthquakeDetail.newInstance(entry);
        getFragmentManager().beginTransaction().add(R.id.earthquake_detail_container, details).commit();
	}
	
	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			outState.putString(CONSTANTS.EARTHQUAKE_JSON, extras.getString(CONSTANTS.EARTHQUAKE_JSON));
		}
	}
}